<?php

namespace App\Models;

use App\Services\CommonService;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;


class BankCard extends Model
{
    use HasFactory;
    protected $table = 'sp_bank_card';
    protected $primaryKey = 'id';
//    public $timestamps = false;
    protected $guarded = [];
    const NODELETE=0;
    const DELETE=1;
    public function getMemberAll($uid)
    {
       $list=$this->where('uid', $uid)
            ->where('contract_no','<>','')
            ->where('is_del',self::NODELETE)
            ->orderBy('id', 'desc')
            ->select('id','bank_name','card_holder_name','bank_code','card_no')
            ->get();
        $list=obToArray($list);
       foreach ($list as $k=>$ra){
           $list[$k]['card_no']=mb_substr($ra['card_no'],0,4,'utf-8').'********'.mb_substr($ra['card_no'],-4,4,'utf-8');
       }
        return $list;
    }



    public static function detail($id,$uid)
    {
        return (new self())::where('contract_no','<>','')->where('is_del',0)->where('id',$id)->where('uid',$uid)->first();
    }


}
